import pageStore from './store';
import { useCallback } from 'react';
import { ProForm, ProFormText, ProFormSelect, ProFormSwitch } from '@ant-design/pro-form';
import AppFormData from '@/components/AppFormData';

interface ProjectManageAddProps {}

/**
 * 添加项目页面
 * @param props
 */
const ProjectManageAdd = (props: ProjectManageAddProps) => {
  const [, pageDispatch] = pageStore.useModel('projectManageAdd');
  const doFinish = useCallback(async function (values) {
    await pageDispatch.add(values);
  }, []);
  return (
    <AppFormData>
      <ProForm onFinish={doFinish} style={{ width: '100%' }}>
        <ProFormText
          name="name"
          label="项目名称"
          rules={[
            {
              max: 30,
              message: '项目名称最大长度是30',
            },
            {
              required: true,
              message: '项目名称不能空',
            },
          ]}
          placeholder="请输入项目名称"
          tooltip="项目名称最大长度30"
        />
        <ProFormText
          name="respository"
          label="仓库地址"
          rules={[
            {
              max: 100,
              message: '仓库地址最大长度是30',
            },
            {
              required: true,
              message: '仓库地址不能空',
            },
          ]}
          placeholder="请输入仓库地址"
          tooltip="仓库地址最大长度30"
        />
        <ProFormSelect
          name="baseProject"
          label="父项目"
          placeholder="请选择父项目地址"
          tooltip="如果有父项目则会依赖父项目进行创建"
        />
        <ProFormSwitch
          name="isMerge"
          label="是否自动合并"
          initialValue={false}
          tooltip="如果有父项目,是否在每次发布时自动合并父项目"
        />
      </ProForm>
    </AppFormData>
  );
};

export default ProjectManageAdd;
